import { app } from 'db://app-game/core/app';
import { ecs } from 'db://app-game/libs/ecs/ECS';
import { GameMVVMName } from '../../../../common/config/GameMVVM';
import { RoleNumericMap } from './attribute/RoleNumericMap';

@ecs.register('RoleModel')
export class RoleModelComp extends ecs.Comp {
  /** 角色属性 */
  attributes: RoleNumericMap = null!;
  constructor() {
    super();
    this.attributes = new RoleNumericMap(this.vm);
  }

  private _chp: number = 0;
  /** 当前血量 */
  get chp(): number {
    return this._chp;
  }
  set chp(value: number) {
    this._chp = value;
    this.vm.chp = value;
  }

  private _cmp: number = 0;
  /** 当前蓝量 */
  get cmp(): number {
    return this._cmp;
  }
  set cmp(value: number) {
    this._cmp = value;
    this.vm.cmp = value;
  }

  /** 提供 VM 组件使用的数据 */
  private vm: any = {};

  vmAdd() {
    app.mvvm.add(this.vm, GameMVVMName.Role);
  }

  vmRemove() {
    app.mvvm.remove(GameMVVMName.Role);
  }

  reset(entity: ecs.Entity): void {
    this.vmRemove();
  }
}
